import surnameArr from '../assets/surnameData.json'

export type GetSurnameParams = {
  counts?: number[]
  struct?: string
  hasDot?: boolean
  hasGou?: boolean
}
export function searchSurname({counts, struct, hasDot, hasGou}: GetSurnameParams = {}) {
  const res = []
  for (let i = 0; i < surnameArr.length; i ++ ) {
    if (i > 300) break; // 限制最多返回300个姓氏

    const item = surnameArr[i];
    if (counts && !counts.includes(item.count)) continue;
    if (struct && item.struct !== struct) continue;
    if (typeof hasDot !== 'undefined') {
      if (hasDot && !item.dotCount) continue;
      if (!hasDot && item.dotCount) continue;
    }
    if (typeof hasGou !== 'undefined') {
      if (hasGou && !item.gouCount) continue;
      if (!hasGou && item.gouCount) continue;
    }

    res.push(item.surname);
  }
  return res;
}

